home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / sound / speech recognition sample / listening.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  2.3 KB  |  76 lines

  1. /*
  2.     File:        Listening.c
  3.  
  4.     Contains:    
  5.  
  6.     Written by:     
  7.  
  8.     Copyright:    Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/2/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. #ifndef __LISTENING__
  24. #include "Listening.h"
  25. #endif
  26.  
  27. OSErr        InitSpeechRecognition    (SpeechInfoPtr theSpeechInfo)
  28. {
  29.     OSErr        theErr        = noErr;
  30.  
  31.     /* Make sure SpeechRecognition Toolbox is available */
  32.     theErr = Gestalt (gestaltSpeechRecognitionVersion, &theSpeechInfo->attributes);
  33.     /* Version number must be at least 1.5 to support Speech Recognition Toolbox API used here. */
  34.     if (theErr == noErr) {
  35.         if (theSpeechInfo->attributes < 0x00000150) {
  36.             theErr = kNotEnoughSpeechVersion;
  37.         }
  38.     }
  39.  
  40.     return theErr;
  41. }
  42.  
  43. OSErr        OpenSpeechRecognition    (SpeechInfoPtr theSpeechInfo)
  44. {
  45.     OSErr        theErr        = noErr;
  46.  
  47.     theErr = SROpenRecognitionSystem (&theSpeechInfo->recogSystem, kSRDefaultRecognitionSystemID);
  48.  
  49.     return theErr;
  50. }
  51.  
  52. OSErr        ConfigureRecognition    (SpeechInfoPtr theSpeechInfo)
  53. {
  54.     OSErr        theErr            = noErr;
  55.     short        feedbackModes    = kSRHasFeedbackHasListenModes;
  56.  
  57.     /* We use the default feedback and listening modes */
  58.     theErr = SRSetProperty (theSpeechInfo->recogSystem, kSRFeedbackAndListeningModes, &feedbackModes, sizeof (feedbackModes));
  59.  
  60.     return theErr;
  61. }
  62.  
  63. OSErr        GetNewRecognizer        (SpeechInfoPtr theSpeechInfo)
  64. {
  65.     OSErr        theErr            = noErr;
  66.     Boolean        forground        = false;        //We want to recognize even if in the background
  67.  
  68.     /* Create a recognizer with default speech source -- e.g. the desktop microphone */
  69.     theErr = SRNewRecognizer (theSpeechInfo->recogSystem, &theSpeechInfo->theRecognizer, kSRDefaultSpeechSource);
  70.     if (theErr == noErr) {
  71.         theErr = SRSetProperty (theSpeechInfo->theRecognizer, kSRForegroundOnly, &forground, sizeof (forground));
  72.     }
  73.  
  74.     return theErr;
  75. }
  76.